﻿@{
    Layout = "~/Modules/LayoutEngine/Views/Shared/_LayoutAdmin.cshtml";
    ViewBag.Title = "选择数据源";
    
    Style.Reqiured("List").AtHead();
    Script.Reqiured("List").AtHead();
}

<script>
        $(function () {
            var _open = window.parent;
            var userId = $(_open.parent.document).find("input[id='hdnCurrentUserId']").val(); //'4a15860d-780e-4511-a558-9b857c1bf1f6';
            // 加载应用List
            $.ajax({
                type: "POST",
                url: "@Urls.ApiHost/api/mp/list/getappbyuserId?t=" + new Date().getMilliseconds(),
                data: {
                    "": userId
                },
                success: function (result) {
                    if (result && result.length > 0) {
                        var html = "";
                        $("#applist").empty();
                        for (var i = 0 ; i < result.length; i++) {
                            var item = result[i];
                            if (i == 0) {
                                loadTables(item["Id"], userId);
                            }
                            
                            var icon = item["ImgClass"];
                            if(!icon){
                                icon = "menu-icon glyphicon glyphicon-tasks";
                            }

                            html += "<li class='dd-item dd2-content' style='padding:0;'>";
                            html += '<a href="#" onclick="loadTables(\'' + item["Id"] + '\',\'' + userId + '\');" class="mymenu" >';
                            html += '<i class="menu-icon ' + icon + '"></i><span class="menu-text"> ' + item["AppSortName"] + ' </span>';
                            html += '</a>';
                            html += '</li>';
                        }
                        $("#applist").append(html);
                    }
                }               
            });

        });

        // 加载应用
        function loadTables(appId,userId) {
            //加载数据
            var d = [{ "Id": "", "opt": "select", "name": "DataManage" },
                     { "item": { "Name": "userid", "Operation": "eq", "Value": userId, "ValueType": "string" } }, //"4a15860d-780e-4511-a558-9b857c1bf1f6"
                     { "item": { "Name": "appid", "Operation": "eq", "Value": appId, "ValueType": "string" } }];  // 59408b80-575c-4533-8276-d9bf74265f84
            doajax("@Urls.ApiHost/api/mp/list/find", d, function (b) {
                if (b) {
                    $("#loading").removeClass("loading");
                    $("#loading").addClass("loading hide");
                    b = JSON.parse(b);
                    b = JSON.parse(b.Message);
                    if (b.length != 0) {
                        $("#form").show();
                        $("#noFormData").hide();
                        $("#form .bs-glyphicons-list").empty();
                        $.each(b, function (i, k) {
                            var li = "";
                            formtype = "";
                            li = "<li onclick='loadList(this)' style=\"width:120px;height:110px;cursor:pointer;background-color:#DBDBDB\" onmouseover=\"this.style.backgroundColor='#C2C2C2'\" onmouseout=\"this.style.backgroundColor='#DBDBDB'\"> <span >" + k.data_table + "</span><br/><br/><span style='display:none'>" + k.data_table + "</span><span style='display:none'>" + appId + "</span></li>";
                            $("#form .bs-glyphicons-list").append(li);
                        })
                    } else {
                        $("#form").hide();
                        $("#noFormData").show();
                    }
                }
            });
        }

        function loadList(k) {
            $("#selected").val("");

            //获取formId
            var formId = "";
            //获取formtype
            var formtype = "";
            //获取code值
            var code = $(k).find("span:eq(1)").html();
            var appId = $(k).find("span:eq(2)").html();
            $("#form .bs-glyphicons-list li").each(function (i, o) {
                if ($(o).find("span:eq(1)").html() == code) {
                    $(o).css('background-color', "#919191");
                    $(o).attr("onmouseover", "");
                    $(o).attr("onmouseout", "");
                } else {
                    $(o).css('background-color', "#DBDBDB");
                    $(o).attr("onmouseover", "this.style.backgroundColor='#C2C2C2'");
                    $(o).attr("onmouseout", "this.style.backgroundColor='#DBDBDB'");
                }
            })

            //加载列表数据
            var d = [{ "Id": "", "opt": "select", "name": "ListManage" }, { "item": { "Name": "userid", "Operation": "eq", "Value": "4a15860d-780e-4511-a558-9b857c1bf1f6", "ValueType": "string" } },
                     { "item": { "Name": "list_code", "Operation": "eq", "Value": code, "ValueType": "string" } }];
            doajax("@Urls.ApiHost/api/mp/list/find", d, function (b) {
                if (b) {
                    b = JSON.parse(b);
                    b = JSON.parse(b.Message);
                    if (b.length != 0) {

                        $("#list").show();
                        $("#listTitle").show();
                        $("#noListData").hide();
                        $("#list .bs-glyphicons-list").empty();
                        $.each(b, function (i, k) {
                            d = [{ "Id": "", "opt": "select", "name": "ListFunBtn" },
                                 { "item": { "Name": "list_id", "Operation": "eq", "Value": k._id.$oid, "ValueType": "string" } }
                            ];
                            var _formid = '';
                            doajax("@Urls.ApiHost/api/mp/list/findfirst", d, function (b1) {
                                if (b1 && b1.length>0) {
                                    b1 = JSON.parse(b1);
                                    b1 = b1["funbtn_title"];

                                    if (b1 && b1.length > 0) {
                                        b1 = JSON.parse(b1);
                                        if (b1) {
                                            for (var i = 0; i < b1.length; i++) {
                                                if (b1[i]["btncode"] == '01') {
                                                    var data = b1[i]["formparams"];
                                                    if (data && data.length > 0) {
                                                        var strs = data.split("|");
                                                        if (strs && strs.length > 2) {
                                                            _formid = strs[0];
                                                            if (k.workflow_status == "") {
                                                                formtype = "4";
                                                            } else {
                                                                formtype = "2";
                                                            }
                                                            $("#list .bs-glyphicons-list").append("<li style=\"width:120px;height:110px;cursor:pointer;background-color:#DBDBDB\" onmouseover=\"this.style.backgroundColor='#C2C2C2'\" onmouseout=\"this.style.backgroundColor='#DBDBDB'\"> <span class=" + k._id.$oid + "  formtype=" + formtype + " wtype=" + k.workflow_status + ">" + k.list_name + "</span><br/><br/><span style='display:none'>" + k.list_code + "</span><span style='display:none'>" + _formid + "</span><span style='display:none'>" + appId + "</span></li>");
                                                        }
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            });
                        })


                    } else {
                        $("#list").hide();
                        $("#listTitle").show();
                        $("#noListData").show();
                    }
                    //添加表单点击事件
                    $("#list .bs-glyphicons-list li").each(function (i, k) {
                        $(k).attr("onclick", "setLinkUrl(this)");
                    })
                }
            })
        }


        function setLinkUrl(k) {
            //获取listId
            var listId = $(k).find("span:eq(0)").attr("class");
            //获取code值
            var listcode = $(k).find("span:eq(0)").html();
            var code = $(k).find("span:eq(1)").html();
            var formid = $(k).find("span:eq(2)").html();
            var appid = $(k).find("span:eq(3)").html();

            // 赋值，关闭弹出框
            var _open = window.parent;
            $(_open.document).find("input[id='ListId']").val(listId);
            $(_open.document).find("input[id='FormCode']").val(code);
            $(_open.document).find("input[id='ListCode']").val(listcode);
            $(_open.document).find("input[id='FormId']").val(formid);
            $(_open.document).find("input[id='AppId']").val(appid);
            $(_open.document).find("div[class='CloseWindow']").click();
        }
    </script>

<div class="page-body">
    <div class="row">
        <div class="col-lg-12 col-sm-12 col-xs-12">
            <div class="row">
                <div class="col-lg-2 col-sm-2 col-xs-12">
                    <div class="widget">
                        <div class="widget-header bg-info">
                            <span class="widget-caption">
                                <a class="notdrag" style="color:#fff">应用列表</a>
                            </span>
                        </div>

                        <div class="widget-body" style="height:426px;">
                            <div class="page-container">
                                <div id="sidebar" style="overflow:auto; max-width:180px;">
                                    <ul id="applist" class="nav sidebar-menu">
                                        @*<li class="myli">
                            <a href="#" onclick="rediectUrl(this);" class="mymenu" o-href="/CMS/admin/Layout">
                                <i class="menu-icon glyphicon glyphicon-align-justify"></i><span class="menu-text">@Html.Lang("布局列表") </span>
                            </a>
                    </li>*@
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-10 col-sm-10 col-xs-12">
                    <div class="widget">
                        <div class="widget-body" style="width:530px;height:460px;">
                            <div style="height: 437px;overflow-y:auto;">
                                <div style=" margin-bottom: 5px;">
                                    <span style="width:100%;font-size:13px;font-weight:bold;">表数据(点击表数据后选择相应列表)</span>
                                </div>
                                <div id="noFormData" style="display:none;">
                                    <span style="color:red;width:100%">暂无表数据！</span>
                                </div>
                                <div id="form" class="bs-glyphicons">
                                    <ul class="bs-glyphicons-list"></ul>
                                </div>
                                <div id="listTitle" style="display:none; margin-top:20px;margin-bottom:5px;">
                                    <span style="width:100%;font-size:13px;font-weight:bold;">列表数据</span>
                                </div>
                                <div id="noListData" style="display:none;">
                                    <span style="color:red;width:100%">暂无列表数据！</span>
                                </div>
                                <div id="list" class="bs-glyphicons" style="display:none">
                                    <ul class="bs-glyphicons-list"></ul>
                                </div>
                            </div>
                            <input id="selected" type="hidden" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




